package com.zp.self.module.level_1_问道.I_Java基础.I_7_JDK8新功能.lambda;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author ：by Zeng Peng
 * @date ：Created 2022/7/19 21:38
 * @description ：
 */
public class TestStream {

    @Test
    public void testGetTargetUsers() {
        List<String> ids = Arrays.asList("205","10","308","49","627","193","111", "193");
        // 使用流操作
        List<Dept> results = ids.stream()
                .filter(s -> s.length() > 2)
                .distinct()
                .map(Integer::valueOf)
                .sorted(Comparator.comparingInt(o -> o))
                .limit(3)
                .map(id -> new Dept(id," "))
                .collect(Collectors.toList());

        Map<Integer, List<Dept>> collect = results.stream().collect(Collectors.groupingBy(Dept::getId));
        System.out.println(results);

    }

}
@Data
@AllArgsConstructor
 class Dept {

    int id;
    String name;
}

